/*
*   Grupo 2:		Ana Elisa Siena			7126563
*                       Larissa Zimmermann		7126879
* 
*   Jogo em Java - AngryBirds
*   SCC - 604 - Programação Orientada a Objetos
*   Prof. Fernando V. Paulovich
*   Engenharia de Computação 010 - USP - São Carlos
*   Segundo Semestre de 2011 
*	
*/

package angrybirds.fases;

import angrybirds.main.Angrybirds;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.Sound;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

public class Perdeu extends BasicGameState {

    private Image Perdeu = null;
    private Image voltarMenu = null;
    private float voltarMenuEscala = 1;
    private Sound Selecao = null;    
    private int stateID = -1;    
    private Sound musicaPerdeu = null;
    private int tocar_barulho = 0;
    

    public Perdeu(int PERDEU) {
        this.stateID = PERDEU;
    }

    @Override
    public int getID() {
        return this.stateID;
    }

    @Override
    public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {

        this.Perdeu = new Image("imagensJogo/FundoPerdeu.jpg");

        this.voltarMenu = new Image("imagensJogo/Botao_Voltar_Menu.png");

        Selecao = new Sound("sons/SelecaoBotoes.wav");
        
        musicaPerdeu = new Sound("sons/Perdeu.wav"); 
    }

    @Override
    public void render(GameContainer gc, StateBasedGame sbg, Graphics grphcs) throws SlickException {

        this.Perdeu.draw(0, 0);

        this.voltarMenu.draw(0, 0, this.voltarMenuEscala);
    }
    public float escala = 0.001f;

    @Override
    public void update(GameContainer gc, StateBasedGame sb, int delta) throws SlickException {

        Input input = gc.getInput();

        int mouseX = input.getMouseX();
        int mouseY = input.getMouseY();

        boolean insideBackmenu = false;
        boolean insidePlaygame = false;
        
        
        if(this.tocar_barulho == 0){
            this.musicaPerdeu.play();
            this.tocar_barulho = 1;
        }

        //Redimenciona Menu, Pause e Recomeçar
        if ((mouseX >= 0 && mouseX <= (this.voltarMenu.getWidth()))
                && (mouseY >= 0 && mouseY <= this.voltarMenu.getHeight())) {
            insideBackmenu = true;
        }

        if (insideBackmenu) {
            if (this.voltarMenuEscala < 1.05f) {
                this.voltarMenuEscala += this.escala * delta;
                Selecao.play();
            }
            //se o click for realizado...
            if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
                sb.enterState(Angrybirds.MAINMENUSTATE);
                this.musicaPerdeu.stop();
                this.tocar_barulho = 0;
            }
        } else {
            if (this.voltarMenuEscala > 1.0f) {
                this.voltarMenuEscala -= this.escala * delta;
            }
        }
    }
}
